USE [notarial]
GO

/****** Object:  Table [dbo].[OrderDocTemplate]    Script Date: 06/20/2011 09:25:00 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

DELETE FROM [dbo].[OrderDocTemplate]

DROP TABLE [dbo].[OrderDocTemplate]

CREATE TABLE [dbo].[OrderDocTemplate](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[OrderId] [int] NOT NULL,
	[Name] [varchar](1000) NOT NULL,
	[Data] [varbinary](max) NOT NULL,
	[Created] [datetime] NOT NULL,
	[CreatorId] [int] NOT NULL,
	[IsDeleted] [bit] NOT NULL,
	[DeletedDate] [datetime] NULL,
	[ParentId] [int] NULL,
	[TemplateTypeId] [int] NOT NULL,
	[IsNotTemp] [bit] NOT NULL,
 CONSTRAINT [PK_OrderDocTemplates] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[OrderDocTemplate]  WITH CHECK ADD  CONSTRAINT [FK_OrderDocTemplate_OrderDocTemplate] FOREIGN KEY([ParentId])
REFERENCES [dbo].[OrderDocTemplate] ([Id])
GO

ALTER TABLE [dbo].[OrderDocTemplate] CHECK CONSTRAINT [FK_OrderDocTemplate_OrderDocTemplate]
GO

ALTER TABLE [dbo].[OrderDocTemplate]  WITH CHECK ADD  CONSTRAINT [FK_OrderDocTemplates_OrderDocTemplates] FOREIGN KEY([OrderId])
REFERENCES [dbo].[Order] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[OrderDocTemplate] CHECK CONSTRAINT [FK_OrderDocTemplates_OrderDocTemplates]
GO

ALTER TABLE [dbo].[OrderDocTemplate]  WITH CHECK ADD  CONSTRAINT [FK_OrderDocTemplates_User] FOREIGN KEY([CreatorId])
REFERENCES [dbo].[User] ([Id])
GO

ALTER TABLE [dbo].[OrderDocTemplate] CHECK CONSTRAINT [FK_OrderDocTemplates_User]
GO

ALTER TABLE [dbo].[OrderDocTemplate] ADD  CONSTRAINT [DF_OrderDocTemplates_IsDeleted]  DEFAULT ((0)) FOR [IsDeleted]
GO

ALTER TABLE [dbo].[OrderDocTemplate] ADD  CONSTRAINT [DF_OrderDocTemplate_IsTemp]  DEFAULT ((0)) FOR [IsNotTemp]
GO


